package com.chenjun.core.service.activiti.impl;

import javax.annotation.Resource;

import org.activiti.engine.IdentityService;
import org.activiti.engine.identity.Group;
import org.springframework.stereotype.Service;

import com.chenjun.core.dao.generator.entity.SysGroup;
import com.chenjun.core.service.activiti.SynGroupToActivitiService;

@Service
public class SynGroupToActivitiServiceImpl implements SynGroupToActivitiService {

	@Resource
	private IdentityService identityService;
	
	@Override
	public void addGroup(SysGroup record) {
		String groupID = record.getId();
		Group group = identityService.createGroupQuery().groupId(groupID).singleResult();
		if(group == null){
			group = identityService.newGroup(groupID);
			group.setType("assignment");
			group.setName(record.getName());
			identityService.saveGroup(group);
		}
	}

	@Override
	public void deleteGroup(String groupID) {
		identityService.deleteGroup(groupID);
	}

}
